package ;
import easelhx.display.Shape;
import easelhx.display.Text;
import easelhx.utils.Ticker;

/**
 * ...
 * @author 
 */

class TextSimpleExample extends Example
{

	var txt:Text;
	var shape:Shape;
	var count:Int;
	
	public function new() 
	{
		super();
		
		count = 0;
	}
	
	override public function run():Void 
	{
		super.run();
		
		// Create a new Text object, and position it on stage:
		txt = new Text("text on the canvas... 0!", "36px Arial", "#FFF");
		txt.x = 100;
		txt.y = 80;
		txt.rotation = 20;
		//txt.outline = true;
		stage.addChild(txt);

		// this shape will be the background for the text:
		shape = new Shape();
		shape.x = txt.x;
		shape.y = txt.y;
		shape.rotation = txt.rotation;
		stage.addChildAt(shape,0);

		// we want to do some work before we update the canvas,
		// otherwise we could use Ticker.addListener(stage);
		Ticker.setFPS(100);
		Ticker.addListener(this);
	}
	
	private function tick() : Void
	{
		count++;

		// update the text:
		txt.text = "text on the canvas... "+count+"!";

		// draw a vector box of the appropriate width behind the text:
		shape.graphics.clear().beginFill("#F00").drawRect(-10, -10, txt.getMeasuredWidth()+20, 36+20);

		// update the stage:
		stage.update();
	}
	
}